$(document).ready(function(){

    var username = tool.getCookie('username');
    if(username){
        $('#nav .top-nav .top-nav-userinfo').empty();
        var str = `
        <a>欢迎您${username}!</a>
        <span>|</span>
        <a class='sign-out'>退出</a>
        <span>|</span>
        <a href="JavaScript:;">消息通知</a>
        `;
        $('#nav .top-nav .top-nav-userinfo').html(str);
    }


    $('#nav .top-nav .top-nav-userinfo>a.sign-out').click(function(){
        var conindex = layer.confirm('你确定要退出吗？',{
            btn:['确定','取消']
        },function(){
            tool.removeCookie('username');
            console.log(222);
            $('#nav .top-nav .top-nav-userinfo').empty();
            var str = `
            <a href="./login.html">登录</a>
            <span>|</span>
            <a href="./register.html">注册</a>
            <span>|</span>
            <a href="JavaScript:;">消息通知</a>
            `;
            $('#nav .top-nav .top-nav-userinfo').html(str);
            layer.close(conindex)
        },function(){
            layer.msg('又留下来了',{
                icon:1,
                time:1000
            });
        });
    });
    

    $(window).scroll(function(){
        if($(window).scrollTop() >= 1000){
            $('#app .home-tool-bar ul .scroll-top').addClass('active');
            
            $('#app .home-tool-bar ul .scroll-top>a').click(function(){
                $(window).scrollTop() = 0;
                return false;
            });

        }else if($(window).scrollTop() < 1000){
            $('#app .home-tool-bar ul .scroll-top').removeClass('active');
        }
    });


    
});